#include <QApplication>
#include <iostream>
#include "Data.hpp"

#include "login.h"
using namespace std;

#include "User.hpp"
#include "BusinessLogic.hpp"
#include "Status.hpp"

void test_login(BusinessLogic *bl)
{
    // Create some username/password pairs to test
    // It's the following mess in C++
    // wouldn't users = [(name1, password1), (name2, password2)] be nice?
    vector<vector<string> > users;

    // Invalid Name
    vector<string> user;
    user.push_back("John");
    user.push_back("bacon");
    users.push_back(user);

    // Valid Name, Valid Password
    user = vector<string>();
    user.push_back("Bob");
    user.push_back("test");
    users.push_back(user);

    // Valid Name, Invalid Password
    user = vector<string>();
    user.push_back("Carl");
    user.push_back("wrong_password");
    users.push_back(user);

    // Run though the users and test loggin in..
    for(vector<vector<string> >::iterator it = users.begin(); it < users.end(); ++it)
    {
        user = *it;
		User userObj(user[0], user[1]); 
        cout << "Testing Login (Name=" << user[0] << ", Password=" << user[1] << ")" << endl;

        switch (bl->login(&userObj))
        {
            case LoginSuccess:
                cout << "Login Successful" << endl;
                break;

            case LoginInvalidUser:
                cout << "Login Failed: Invalid User" << endl;
                break;

            case LoginInvalidPassword:
                cout << "Login Failed: Invalid Password" << endl;
                break;
			case LoginFailure:
				cout << "Login Failed" << endl;
				break;
			default:
				cout << "Sumthin funkys goin on" << endl;
				break;
        }
    }	
}

int main(int argc, char *argv[])
{
    if (argc == 1) 
		return -1;

	BusinessLogic* bl = BusinessLogic::singleton();
	bl->createDatabase(argv[1]);

    Gui gui(argc, argv);
	gui.startLogin();

    return 0;
}
